import request from '@/utils/request'
export function getTreeLabel(childOptions, id){
   let label = null;
    for(var i=0;i<childOptions.length;i++){
      if(childOptions[i].id ==parseInt(id)){
        label = childOptions[i].label;
        break;
      }else if(childOptions[i].children){
        label = getTreeLabel(childOptions[i].children, id);
        if(label){
          break;
        }
      }
    }
    return label;
}

export function getTreeNode(childOptions, id){
   let treeNode = null;
    for(var i=0;i<childOptions.length;i++){
      if(childOptions[i].id ==parseInt(id)){
        treeNode = childOptions[i];
        break;
      }else if(childOptions[i].children){
        treeNode = getTreeNode(childOptions[i].children, id);
        if(treeNode){
          break;
        }
      }
    }
    return treeNode;
}
// 查询机构列表
export function listOrgnization(query) {
  return request({
    url: '/labdata/orgnization/list',
    method: 'get',
    params: query
  })
}

//orgName
export function getOrgName(orgId) {
  return request({
    url: '/labdata/orgnization/orgName/'+orgId,
    method: 'get'
  })
}
// 查询所选机构列表
export function getCheckedList(query) {
  return request({
    url: '/labdata/orgnization/getCheckedList',
    method: 'get',
    params: query
  })
}

//sublist
export function listSubOrgnization(query) {
  return request({
    url: '/labdata/orgnization/sublist',
    method: 'get',
    params: query
  })
}
//platformlist
export function listPlatformOrgnization(query) {
  return request({
    url: '/labdata/orgnization/platformlist',
    method: 'get',
    params: query
  })
}

//thirdlist
export function listThirdOrgnization(query) {
  return request({
    url: '/labdata/orgnization/thirdlist',
    method: 'get',
    params: query
  })
}
//rootlist
export function listRootOrgnization(query) {
  return request({
    url: '/labdata/orgnization/rootlist',
    method: 'get',
    params: query
  })
}
//getThirdLab
export function getThirdLab() {
  return request({
    url: '/labdata/orgnization/listOrgByFuntionOpt/4',
    method: 'get'
  })
}

//getOrgByFunctionOpt
export function getOrgByFunctionOpt(functionOpt) {
  return request({
    url: '/labdata/orgnization/listOrgByFuntionOpt/'+functionOpt,
    method: 'get'
  })
}
///searchLab/{orgName}
export function searchUserLab(orgName) {
  return request({
    url: '/labdata/orgnization/searchOrg/'+orgName,
    method: 'get'
  })
}
//listSecondOrgLab/{orgId}
export function listSecondOrgLab(orgId) {
  return request({
    url: '/labdata/orgnization/listSecondOrgLab/'+orgId,
    method: 'get'
  })
}
// 查询机构详细
export function getOrgnization(orgId) {
  return request({
    url: '/labdata/orgnization/' + orgId,
    method: 'get'
  })
}

// 新增机构
export function addOrgnization(data) {
  return request({
    url: '/labdata/orgnization',
    method: 'post',
    data: data
  })
}

// 修改机构
export function updateOrgnization(data) {
  return request({
    url: '/labdata/orgnization',
    method: 'put',
    data: data
  })
}

// 删除机构
export function delOrgnization(orgId) {
  return request({
    url: '/labdata/orgnization/' + orgId,
    method: 'delete'
  })
}

// 导出机构
export function exportOrgnization(query) {
  return request({
    url: '/labdata/orgnization/export',
    method: 'get',
    params: query
  })
 }


 // 获取部门下拉树列表
export function treeselect(query) {
  return request({
    url: '/labdata/orgnization/treeselect',
    method: 'get',
    params: query
  })
}
//platformTree
//获取平台下拉树列表
export function platformTree() {
  return request({
    url: '/labdata/orgnization/platformTree',
    method: 'get'
  })
}
